#include "comm.hpp"

int main()
{
    // 创建共享内存
    int shmid = GetShm();
    
    // 挂接共享内存
    char *shmaddr = (char *)shmat(shmid, nullptr, 0);

    // 打开信道
    int fd = open(FIFO_FILE, O_WRONLY);  
    //std::cout<<fd<<std::endl;
    if (fd < 0)
    {
        log(Fatal, "error string: %s  error code: %d", strerror(errno), errno);
        exit(FIFO_OPEN_ERR);
    }


    //ipc code  共享内存一旦被创建，直接被当成一块内存空间使用，不需要再调用系统调用
    while(true)
    {
        std::cout<<"Please Enter@";
        fgets(shmaddr,4096,stdin);

        write(fd,"c",1);
        
    }


    //去关联
    shmdt(shmaddr);

    close(fd);
    
    return 0;
}